$(function(){
	Key.registerKeyBom("alt+1",function(){
		prompt(location.href,location.href);
	});
	Key.registerKeyBom("alt+2",function(){
		var sReturn=RunJavaMethod('platform.generalTools','reloadSRE');
		if("SUCCESS"==sReturn){
			alert("刷新成功!");
		}else{
			alert("刷新失败!");
		}
	});
	Key.registerKeyBom("alt+3",function(){alert("alt+3");});
	Key.registerKeyBom("ctrl+s", function() {
		doSave();
	});
	Key.call();
});

function doSave(){
}
(function (window, undefined ){
var Key={
		keyHistory:new Array(),
		keyBom:new Array(),//快捷键及其调用事件
		//注册快捷键事件
		registerKeyBom:function(keyBomStr,callback){
			//_.i("注册快捷键:"+keyBomStr);
			var flag=false;
			for(var index=0;index<Key.keyBom.length;index++){
				if(Key.keyBom[index]['name']==keyBomStr.toUpperCase()){
					Key.keyBom[index]['event']=callback;
					flag=true;
					break;
				}
			}
			if(!flag){
				Key.keyBom.push({name:keyBomStr.toUpperCase(),'event':callback});
			}
		},
		//唤醒按键记录功能
		call:function(){
			//_.i("启动快捷键监听");
			$(window).keydown(function(e){
				if(Key.keyHistory.length>0){
					if(Key.keyHistory[Key.keyHistory.length-1]!=Key.getCodeKey(e.keyCode)){//重复按键忽略
						Key.keyHistory.push(Key.getCodeKey(e.keyCode));
					}
				}else{
					Key.keyHistory.push(Key.getCodeKey(e.keyCode));
				}
				for(var i=0;i<Key.keyBom.length;i++){
					for(keyBom in Key.keyBom[i]){
						//console.log("快捷键:"+Key.keyHistory.join("+"));
						if(Key.keyHistory.join("+")==Key.keyBom[i][keyBom]){
							//_.i("快捷键:"+Key.keyHistory.join("+"));
							Key.keyHistory.length=0;
							var e=Key.keyBom[i]['event'];
							e();
						}
					}	
				}
			});
			$(window).keyup(function(e){
				Key.keyHistory.length=0;
			});
		},
		getKeyCode : function(char){//根据字符获得键值
			char = char.toUpperCase();
			if(char=='F1') return 112;
			if(char=='F2') return 113;
			if(char=='F3') return 114;
			if(char=='F4') return 115;
			if(char=='F5') return 116;
			if(char=='F6') return 117;
			if(char=='F7') return 118;
			if(char=='F8') return 119;
			if(char=='F9') return 120;
			if(char=='F10') return 121;
			if(char=='F11') return 122;
			if(char=='F12') return 123;
			
			if(char=='DEL' || char=='DELETE') return 46;
			if(char=='ALT')return 18;
			if(char=='CTRL')return 17;
			
			if(char=='0') return 48;
			if(char=='1') return 49;
			if(char=='2') return 50;
			if(char=='3') return 51;
			if(char=='4') return 52;
			if(char=='5') return 53;
			if(char=='6') return 54;
			if(char=='7') return 55;
			if(char=='8') return 56;
			if(char=='9') return 57;
			
			if(char=='A') return 65;
			if(char=='B') return 66;
			if(char=='C') return 67;
			if(char=='D') return 68;
			if(char=='E') return 69;
			if(char=='F') return 70;
			if(char=='G') return 71;
			if(char=='H') return 72;
			if(char=='I') return 73;
			if(char=='J') return 74;
			if(char=='K') return 75;
			if(char=='L') return 76;
			if(char=='M') return 77;
			if(char=='N') return 78;
			if(char=='O') return 79;
			if(char=='P') return 80;
			if(char=='Q') return 81;
			if(char=='R') return 82;
			if(char=='S') return 83;
			if(char=='T') return 84;
			if(char=='U') return 85;
			if(char=='V') return 86;
			if(char=='W') return 87;
			if(char=='X') return 88;
			if(char=='Y') return 89;
			if(char=='Z') return 90;
		},
		getCodeKey : function(key){//根据键值获得字符
			if(key==112) return 'F1';
			if(key==113) return 'F2';
			if(key==114) return 'F3';
			if(key==115) return 'F4';
			if(key==116) return 'F5';
			if(key==117) return 'F6';
			if(key==118) return 'F7';
			if(key==119) return 'F8';
			if(key==120) return 'F9';
			if(key==121) return 'F10';
			if(key==122) return 'F11';
			if(key==123) return 'F12';
			
			if(key==46) return 'DEL';
			if(key==18)return 'ALT';
			if(key==17)return 'CTRL';
			
			if(key==48) return '0';
			if(key==49) return '1';
			if(key==50) return '2';
			if(key==51) return '3';
			if(key==52) return '4';
			if(key==53) return '5';
			if(key==54) return '6';
			if(key==55) return '7';
			if(key==56) return '8';
			if(key==57) return '9';
			
			if(key==65) return 'A';
			if(key==66) return 'B';
			if(key==67) return 'C';
			if(key==68) return 'D';
			if(key==69) return 'E';
			if(key==70) return 'F';
			if(key==71) return 'G';
			if(key==72) return 'H';
			if(key==73) return 'I';
			if(key==74) return 'J';
			if(key==75) return 'K';
			if(key==76) return 'L';
			if(key==77) return 'M';
			if(key==78) return 'N';
			if(key==79) return 'O';
			if(key==80) return 'P';
			if(key==81) return 'Q';
			if(key==82) return 'R';
			if(key==83) return 'S';
			if(key==84) return 'T';
			if(key==85) return 'U';
			if(key==86) return 'V';
			if(key==87) return 'W';
			if(key==88) return 'X';
			if(key==89) return 'Y';
			if(key==90) return 'Z';
		}
};
window.Key=window.k=Key;
})(window);